﻿//AcademicPlanner - course registration planning web app.
//Copyright (C) 2009  Boubacar Diallo

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


using System;
using System.Collections.Specialized;
using System.Configuration;


namespace AcademicPlanner.Framework.Helpers
{
	/// <summary>
	/// ConfigHelper provides static helper methods to access the application's
	/// configuration.
	/// </summary>
	/// <since>1.0</since>
	public static class ConfigHelper
	{
		private static readonly string configSectionPathFormat = "academicplanner/{0}/{1}";

		/// <summary>
		/// Gets the collection of configuration settings for a section
		/// in the application's configuration xml.
		/// </summary>
		/// <param name="pSectionPath">The full path to the section (kind of XPath to the section).</param>
		/// <returns>The collection of configuration settings for the section or <c>null</c>.</returns>
		/// <since>1.0</since>
		public static object GetConfigSection(string pSectionPath)
		{
			return ConfigurationSettings.GetConfig(pSectionPath);
		}

		/// <summary>
		/// Gets the collection of configuration settings for a section
		/// in the domain layer group section of the application's configuration xml.
		/// </summary>
		/// <param name="pSection">The relative name of the section.</param>
		/// <returns>The collection of configuration settings for the section or <c>null</c>.</returns>
		/// <since>1.0</since>
		public static NameValueCollection GetDomainConfigSection(string pSection)
		{
			return (NameValueCollection)GetConfigSection(string.Format(configSectionPathFormat,
															"academicplanner.domain", pSection));
		}

		/// <summary>
		/// Gets the value of a configuration setting in section of the
		/// domain layer group section of the application's configuration xml.
		/// </summary>
		/// <param name="pSection">The relative name of the section.</param>
		/// <param name="pItem">The configuration setting key.</param>
		/// <returns>The value of a configuration setting.</returns>
		/// <since>1.0</since>
		public static object GetDomainSectionValue(string pSection, string pItem)
		{
			return GetDomainConfigSection(pSection)[pItem];
		}

		/// <summary>
		/// Gets the collection of configuration settings for a section
		/// in the presentation layer group section of the application's configuration xml.
		/// </summary>
		/// <param name="pSection">The relative name of the section.</param>
		/// <param name="pItem">The configuration setting key.</param>
		/// <returns>The value of a configuration setting.</returns>
		/// <since>1.0</since>
		public static object GetPresentationSectionValue(string pSection, string pItem)
		{
			return GetPresentationConfigSection(pSection)[pItem];
		}

		/// <summary>
		/// Gets the collection of configuration settings for a section
		/// in the presentation layer group section of the application's configuration xml.
		/// </summary>
		/// <param name="pSection">The relative name of the section.</param>
		/// <returns>The collection of configuration settings for the section or <c>null</c>.</returns>
		/// <since>1.0</since>
		public static NameValueCollection GetPresentationConfigSection(string pSection)
		{
			return (NameValueCollection)GetConfigSection(string.Format(configSectionPathFormat,
															"academicplanner.presentation", pSection));
		}
	}
}
